<?php
/**
 * Created by PhpStorm.
 * User: 陈森
 * Date: 2020/12/24
 * Time: 15:49
 */

namespace app\admin\controller\order;


use app\admin\model\order\OrderModel;
use core\basic\Controller;

class OrderController extends Controller
{

    protected $model;

    public function __construct()
    {
        $this->model = new OrderModel();

    }
    public function index()
    {
        if ($_POST) {
            $data = array(
                'amount' => post('amount'),
                'poundage' => post('poundage'),
                'start_time' => post('start_time'),
                'end_time' => post('end_time'),
                'unit_price' => post('unit_price'),
                'status' => post('status'),
            );
            if (!$data['start_time']) {
                error('请选择开始时间！', -1);
            }
            if (strtotime($data['start_time']) >= strtotime($data['end_time'])) {
                error('时间选择错误！', -1);
            }
            if (strtotime($data['start_time']) < strtotime(get_datetime())) {
                error('开始时间不能大于当前时间', -1);
            }
            if (!$data['end_time']) {
                error('请选择结束时间！', -1);
            }
            if ($this->model->checkOrder()) {
                if ($this->model->modOrder($data)) {
                    $this->log('修改O2O订单成功！');
                    success('修改成功！', -1);
                } else {
                    error('修改失败!',-1);
                }
            } else {

                if ($this->model->addOrder($data)) {
                    $this->log('修改O2O订单失败！');
                    success('修改成功！', -1);
                } else {
                    error('修改失败!',-1);
                }
            }
        }
        $this->assign('order', $this->model->checkOrder());
        $this->display('order/index.html');
    }
}